package com.ymatou.app.api.testcase;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.api.service.TokenLoginAuthCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.utils.JsonBeanHelper;


/**
*token
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_TokenLoginAuth{
	private static TokenLoginAuthCall tokenloginauthCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家Token");
	}

	@Before
	public void caseUp() {
		tokenloginauthCall=new TokenLoginAuthCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(tokenloginauthCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void TC_TokenLoginAuth_001() {
		Logger.start(true,"获取买家Token");
		try {
		 
			Map<String, Object> map = new HashMap<String, Object>();		
			map.put("UserName","jane" );			    
			map.put("Password","123456");
			
		  
			//调用接口json文件
			JSONObject tooken =  JsonBeanHelper.getJsonBean("/com.ymatou.app.api.LoginAuth/LoginAuth/LoginAuthtpl.json");
			tooken = JsonBeanHelper.updateJsonBean(tooken, map); 		
			JSONObject result = tokenloginauthCall.callAndGetReturnData(tooken);     	
			
			String dataStr=tokenloginauthCall.getReturnData();	
			
			
			Logger.verifyNotNull(dataStr, "返回报文非空");
			String code =  new JSONObject(dataStr).getString("Code");
			Logger.verifyNotNull(code, "200");
			String AccessToken =  new JSONObject(dataStr).getJSONObject("Data").getString("AccessToken");
			Logger.verifyNotNull(AccessToken, "不为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}